package com.centling.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.centling.business.OfflinemeasureVO;
import com.centling.dao.ICustomerDAO;
import com.centling.dao.IOfflinemeasureDAO;
import com.centling.dao.IUtilsDAO;
import com.centling.service.IOfflinemeasureService;

@Service
@Transactional
public class OfflinemeasureService implements IOfflinemeasureService{

	private Logger log = Logger.getLogger(OfflinemeasureService.class);
	
	@Resource
	private IOfflinemeasureDAO offlinemeasureDAO;
	
	@Resource
	private ICustomerDAO customerDAO;
	
	@Resource
	private IUtilsDAO utilsDAO;

	@Transactional
	public boolean save(List<OfflinemeasureVO> offlinemeasures) {
		log.info("save function invoke...");
		for (OfflinemeasureVO olm:offlinemeasures){
			int fID = utilsDAO.getICMaxNum("t_appoint");
			int fItemID = customerDAO.getFItemID(Integer.valueOf(olm.getDsuserid()));
			if (fID!=-1 && fItemID!=-1){
				offlinemeasureDAO.save(olm,fID,fItemID);
				utilsDAO.setICMaxNum("t_appoint");
				return true;
			}
			return false;
		}
		return false;
	}

}
